#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;

class Node {
public:
	string data;
	Node* next;
	Node() {
		data = {};
		next = NULL;
	}
	Node(string num, Node* link = NULL) {
		data = num;
		next = link;
	}
};

class SqList {
private:
	Node* head;
public:
	SqList() {
		head = new Node();
		Node* p = head;

		ifstream ifs;
		ifs.open("article.txt", ios::in);
		char s[10];
		memset(s, 0, sizeof(s));
		string buf;
		while (ifs >> buf) {
			int i = 0, j = 0;
			for (i = 0; i < buf.size(); i++) {
				if (buf[i] >= 'a' && buf[i] <= 'z' || buf[i] >= 'A' && buf[i] <= 'Z') {
					s[j] = tolower(buf[i]);
					j++;
				}
				else {
					if (j != 0) {
						p->next = new Node(s);
						p = p->next;
						memset(s, 0, sizeof(s));
						j = 0;
					}
				}
				if (i + 1 == buf.size() && j != 0) {
					p->next = new Node(s);
					p = p->next;
					memset(s, 0, sizeof(s));
					j = 0;
				}
			}
		}
//		p = head->next;
//		while (p != NULL) {
//			cout << p->data << endl;
//			p = p->next;
//		}
	}
	void sort() {
		Node* p = head->next;
		Node* q;
		string s;

		if (p == NULL)
			return;
		

		while (p->next != NULL) {
			q = p->next;
			while (q != NULL) {
				if (p->data.compare(q->data) > 0) {
					s = p->data;
					p->data = q->data;
					q->data = s;
				}
				q = q->next;
			}
			p = p->next;
		}

	}
	void calculate() {
		Node* p = head->next;
		int num = 0;
		string s;

		while(p != NULL) {
			num++;
			s = p->data;
			p = p->next;
			if (p == NULL || p->data != s) {
				cout << s << " " << num << endl;
				num = 0;
			}
		}
	}
};

int main() {
	SqList S;
	S.sort();
	S.calculate();
	return 0;
}